package cn.lngaosu.lwyd.module.integration.dal.mysql.weixinuser;

import java.util.*;

import cn.lngaosu.lwyd.framework.common.pojo.PageResult;
import cn.lngaosu.lwyd.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.lngaosu.lwyd.framework.mybatis.core.mapper.BaseMapperX;
import cn.lngaosu.lwyd.module.integration.dal.dataobject.weixinuser.WeixinUserDO;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.ibatis.annotations.Mapper;
import cn.lngaosu.lwyd.module.integration.controller.admin.weixinuser.vo.*;

/**
 * 微信公众号用户基本信息 Mapper
 *
 * @author 张恒
 */
@Mapper
public interface WeixinUserMapper extends BaseMapperX<WeixinUserDO> {

    default PageResult<WeixinUserDO> selectPage(WeixinUserPageReqVO reqVO) {
        Long[] subscribeTime = reqVO.getSubscribeTime();
        Long[] subscribeTimeList = null;
        if (ObjectUtils.isNotEmpty(subscribeTime) && subscribeTime.length == 2) {
            subscribeTimeList = new Long[2];
            subscribeTimeList[0] = subscribeTime[0]/1000;
            subscribeTimeList[1] = subscribeTime[1]/1000;
        }
        return selectPage(reqVO, new LambdaQueryWrapperX<WeixinUserDO>()
                .betweenIfPresent(WeixinUserDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(WeixinUserDO::getSubscribe, reqVO.getSubscribe())
                .eqIfPresent(WeixinUserDO::getOpenid, reqVO.getOpenid())
                .eqIfPresent(WeixinUserDO::getLanguage, reqVO.getLanguage())
                .betweenIfPresent(WeixinUserDO::getSubscribeTime, subscribeTimeList)
                .eqIfPresent(WeixinUserDO::getUnionid, reqVO.getUnionid())
                .eqIfPresent(WeixinUserDO::getRemark, reqVO.getRemark())
                .eqIfPresent(WeixinUserDO::getGroupid, reqVO.getGroupid())
                .eqIfPresent(WeixinUserDO::getTagidList, reqVO.getTagidList())
                .eqIfPresent(WeixinUserDO::getSubscribeScene, reqVO.getSubscribeScene())
                .eqIfPresent(WeixinUserDO::getQrScene, reqVO.getQrScene())
                .eqIfPresent(WeixinUserDO::getQrSceneStr, reqVO.getQrSceneStr())
                .orderByDesc(WeixinUserDO::getId));
    }

}